package com.anti.modular.sys.consts.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.api.Result;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.sys.consts.param.SysConfigParam;
import com.anti.modular.sys.consts.service.SysConfigService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 参数配置控制器
 */
@RestController
@RequestMapping("sysConfig")
public class SysConfigController {

    @Resource
    private SysConfigService sysConfigService;

    /**
     * 分页查询配置列表
     */
    @Permission
    @GetMapping("page")
    @BusinessLog(title = "系统参数配置_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam,SysConfigParam sysConfigParam) {
        return Result.data(sysConfigService.page(pageParam,sysConfigParam));
    }

    /**
     * 系统参数配置列表
     */
    @Permission
    @GetMapping("list")
    @BusinessLog(title = "系统参数配置_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result list(SysConfigParam sysConfigParam) {
        return Result.data(sysConfigService.list(sysConfigParam));
    }

    /**
     * 查看系统参数配置
     */
    @Permission
    @GetMapping("detail")
    @BusinessLog(title = "系统参数配置_详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public Result detail(@Validated(SysConfigParam.detail.class) SysConfigParam sysConfigParam) {
        return Result.data(sysConfigService.detail(sysConfigParam));
    }

    /**
     * 添加系统参数配置
     */
    @Permission
    @PostMapping("add")
    @BusinessLog(title = "系统参数配置_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(SysConfigParam.add.class) SysConfigParam sysConfigParam) {
        sysConfigService.add(sysConfigParam);
        return Result.success("增加成功");
    }

    /**
     * 删除系统参数配置
     */
    @Permission
    @PostMapping("delete")
    @BusinessLog(title = "系统参数配置_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(SysConfigParam.delete.class) SysConfigParam sysConfigParam) {
        sysConfigService.delete(sysConfigParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑系统参数配置
     */
    @Permission
    @PostMapping("edit")
    @BusinessLog(title = "系统参数配置_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(SysConfigParam.edit.class) SysConfigParam sysConfigParam) {
        sysConfigService.edit(sysConfigParam);
        return Result.success("编辑成功");
    }

}


